const mysql=require("mysql");
const db=require("../controller/config").database;
const pool=mysql.createPool(db);

console.log(db)
const query=function(sql,sucCb,errCb){
  pool.getConnection((err,conn)=>{
    if(err){
      let data = {
        code:500,
        message:"请求失败",
        data:err
      };
      errCb(data);
    }else{
      conn.query(sql,(err,result)=>{
        if(err){
          console.log("error="+err)
          let data = {
            code:500,
            message:"请求失败",
            data:err
          };
          errCb(data);
        }else{
          sucCb(result);
          conn.release();
        }
      })
    }
  })
}
module.exports=query;